<?php

class Form extends TemplateLoader
{
	public $Name = 'undefined'; // the name of the element in the html plus the formname in the request
	public $Method = 'post'; // method
	public $Action = ''; // action
	public $Class = ''; // CSS Class
	public $ButtonText = 'Submit'; // caption of the submit button
	public $Controls = array( ); // the form controls 
	public $Messages = array( ); // the form messages
	public $HideControls = false;
	public function Form()
	{
		parent::__construct( );
		
		$this->Module = 'System/Controls/Forms';
		$this->Template = 'templates/Form.tpl';
	}
	public function LoadPostData( )
	{
		$success = true;
		if(isset($_POST['formname']) && $_POST['formname'] == $this->Name)
		{
			foreach($this->Controls as $c)
				if(method_exists($c, 'LoadPostData'))
					if( !$c->LoadPostData( ) )
						$success = false;
		}
		else 
			$success = false;
		return $success;
	}
	public function RenderControls( )
	{
		if(!$this->HideControls)
			foreach($this->Controls as $c)
				$c->Render();
	}
}
